"""
api接口测试
"""
import json
import requests
from pathlib import Path
from logparse.log_parse import LogParser

# api_url = 'http://172.18.0.94:5001'
api_url = 'http://localhost:5000'


def llm_answer_test():
    url = f'{api_url}/chat/llmAnswer'
    data = {
        "prompt": "合同审查应该怎么搞? 以JSON 格式返回结果",
        "parse_type": "dict"
    }
    req = requests.post(url, data=json.dumps(data))
    print(json.dumps(req.json(), ensure_ascii=False, indent=4))


def contract_parse_test():
    url = f'{api_url}/chat/contractParse'

    # 获取输入数据
    log_file = Path(__file__).parent.parent / 'logs' / 'debug (6).log'
    parser = LogParser(log_file)
    input_datas = parser.get_input_datas()
    data = parser.find_data_by_id(input_datas, file_id="f39e33ca8574840c8b17f27f631f7609b")

    req = requests.post(url, data=json.dumps(data))
    print(json.dumps(req.json(), ensure_ascii=False, indent=4))


def recall_test():
    url = f'{api_url}/chat/recall'
    data = {
        'fileId': 'dad6204ebdb84513b3afb175e462b',
        'rule': {
            "id": "ff9a0f286e6fb4b7a9db0d42f9264a3ad",
            "name": "违约责任",
            "extractHint": ""
        }
    }
    req = requests.post(url, data=json.dumps(data))
    print(json.dumps(req.json(), ensure_ascii=False, indent=4))


def extract_test():
    url = f'{api_url}/chat/rule'
    data = {
        'fileId': 'dad6204ebdb84513b3afb175e462b',
        'rule': {
            "id": "ff9a0f286e6fb4b7a9db0d42f9264a3ad",
            "name": "违约责任",
            "extractHint": ""
        }
    }
    req = requests.post(url, data=json.dumps(data))
    print(json.dumps(req.json(), ensure_ascii=False, indent=4))


def review_test():
    url = f'{api_url}/chat/rule'
    data = {
        'fileId': 'dad6204ebdb84513b3afb175e462b',
        'rule': {
            "id": "ff9a0f286e6fb4b7a9db0d42f9264a3ad",
            "name": "合同生效",
            "extractHint": "",
            "checkHint": "是否约定了合同生效条款？"
        }
    }
    req = requests.post(url, data=json.dumps(data))
    print(json.dumps(req.json(), ensure_ascii=False, indent=4))


if __name__ == '__main__':
    # llm_answer_test()
    contract_parse_test()
    # recall_test()
    # extract_test()
    # review_test()



